package com.epam.task.web.dao;

import com.epam.task.web.app.ConnectionToDB;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ExecuteQueryToDB {
    public static final Logger LOGGER = LoggerFactory.getLogger(ConnectionToDB.class);
    public static void main(String[] args) {
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            Class.forName("org.gjt.mm.mysql.Driver");
            con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/test",
                    "root", "");
            st = con.createStatement();
            rs = st.executeQuery("SELECT * FROM oc_product");
            while (rs.next()) {
               LOGGER.info(rs.getInt(1) + " " + rs.getString(2) + "" + rs.getInt(3));
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (rs != null) rs.close();
                if (st != null) st.close();
                if (con != null) con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
